//
//  ZJRBTextFliedView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/14.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJRBTextFliedView.h"

//默认高度90
@implementation ZJRBTextFliedView

- (instancetype)initWithFrame:(CGRect)frame  title:(NSString *)title
{
    self = [super initWithFrame:frame title:title];
    if (self) {
        [self addSubview:self.textField];
    }
    return self;
}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (self.isNumber) {
        BOOL isInt = [NSString validateNumber:string];
        if (!isInt) {//不是数字
            return NO;
        }
    }
    
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];

    if (toBeString.length >= self.maxNumber && range.length!= 1 && self.maxNumber > 0){
        textField.text = [toBeString substringToIndex:self.maxNumber];
        return NO;
    }
    return YES;
}





- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];//取消第一响应者
    
    return YES;
}
#pragma mark - getter
- (UITextField *)textField{
    if (_textField == nil){
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(self.titleLabel.x, self.titleLabel.bottom, self.width - 2 * self.titleLabel.x, 44 * [UIScreen zj_screenHScale])];
        [_textField setTextFieldLeftforWidth:13 * [UIScreen zj_screenWScale]];
        [_textField setTextFieldRightforWidth:13 * [UIScreen zj_screenWScale]];
        _textField.placeholder = @"请输入内容...";
        _textField.textColor = [UIColor textBlackColor];
        _textField.font = [UIFont titleTextFont];
        _textField.layer.cornerRadius = normalCornerRadius;
        _textField.layer.borderColor = [UIColor textBlackColor].CGColor;
        _textField.layer.borderWidth = normalBorderWidth;
        _textField.returnKeyType = UIKeyboardTypeTwitter;
        _textField.delegate = self;
    }
    return _textField;
}



@end
